<?php

// echo "hello world";

/*
// demo1:

// 1. 设置连接数据库必要的: servername, username, password
$servername = "localhost";
$username = "root";
$password = "020913";

// 2. 开始连接：conn 为新 new 出来的一个数据库连接
$conn = new mysqli($servername, $username, $password);
if($conn->connect_error){
    die("连接失败：".$conn->connect_error."<br>");
}else{
    echo "连接成功"."<br>";
    // 关闭连接
    $conn->close(); 
}

*/


// 
// demo2:

// $servername = "localhost";
// $username = "root";
// $password = "020913";
// $dbname = "myphpmysql"; // 数据库名称

// $conn = new mysqli($servername, $username, $password, $dbname);
// if($conn->connect_error){
//     die("连接失败: ".$conn->connect_error);
// }

// 插入
// $sql = "insert into username (uid, username) values(3, 'nihao')";
// if($conn->query($sql) === true){
//     echo "新记录插入成功";
// }else{
//     echo "Error: ".$sql."<br>".$conn->error;
// }

// 删除
// $sql = "delete from username where username = 'nihao'";
// mysqli_query($conn, $sql);
// echo "删除成功";

// 查
// $sql = "select * from username";
// $result = $conn->query($sql);
// if($result){
//     $res = $result->fetch_all();
//     var_dump($res);

//     // 打印大页面上
//     foreach($res as $k=>$v){
//         echo "key = " . $k . ", value = " . $v[1] . $v[2] . $v[3];
//         echo "<br>";
//     }
// }

// $conn->close();


